package com.qf.kele02.config;

import com.qf.kele02.intercepto.AutoLoginInterceptor;
import com.qf.kele02.intercepto.MyInterceptor;
import com.qf.kele02.service.UserSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

	@Autowired
	MyInterceptor myInterceptor;

	@Qualifier(value="userServicePlusImp")
	@Autowired
	UserSevice userSevice;

	/**
	 * 添加自定义拦截器
	 *
	 * @param registry
	 */
	@Override
	public void addInterceptors( InterceptorRegistry registry ) {
		AutoLoginInterceptor autoLoginInterceptor=new AutoLoginInterceptor( );
		autoLoginInterceptor.setUserService( userSevice );
		registry.addInterceptor( myInterceptor )  // 拦截器对象
				.addPathPatterns( "/**" )  // 要拦截的路径
				.excludePathPatterns( "/login.html","/regist.html","/kaptcha/**","/layui/**","/user/regist","/user/login" );  // 要放行的路径
		registry.addInterceptor( autoLoginInterceptor ).addPathPatterns( "/login.html" );
	}
}
